package com.vsd.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.dialet.PaginationSupport;
import com.demo.domain.Feedback;
import com.demo.util.SqlUtils;
import com.demo.util.StringUtil;
import com.vsd.daoEx.model.FeedBackEx;
import com.vsd.repository.FeedBackRepository;
import com.vsd.service.FeedBackService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户服务接口实现
 * 
 * @author jiekechoo
 *
 */
@Service
@Transactional
public class FeedBackServiceImpl implements FeedBackService {
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory
			.getLogger(FeedBackServiceImpl.class);
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@Autowired
	private FeedBackRepository feedBackRepository;

	@Override
	public void save(Feedback feedback) {
		// TODO Auto-generated method stub
		feedback.setId(StringUtil.getUUID());
		feedBackRepository.save(feedback);
	}

	@Override
	public List<FeedBackEx> selectExList() {
		// TODO Auto-generated method stub
		String sql = "select f.*,u.nick_name as nickName,u.image as headImg from b_feedback f left join f_user u on f.user_id = u.id order by f.create_time desc";
		
		sql = PaginationSupport.initPage(sql, jdbcTemplate);
		
		List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
		List<FeedBackEx> ret = new ArrayList<>();
		for (Map<String, Object> map : maps) {
			FeedBackEx ex = new FeedBackEx();
			SqlUtils.transMap2Bean2(map, ex);
			ret.add(ex);
		}
		return ret;
	}

	@Override
	public void delById(String id) {
		// TODO Auto-generated method stub
		feedBackRepository.delete(id);
	}

 
	
}
